<?php 
	require 'Model.php';
	class indexModel extends Model{
		function __Construct(){
			parent::__Construct();
		}

		//获取视频类别列表
		function getfoodtype(){
			$sql="select * from foodtype";
			$ft_list = $this->conn->query($sql);
			return $ft_list;
		}
		//获取点击排行列表
		function gethittimes(){
			$sql="select * from foods order by hittimes desc limit 0,4";
			$hits_list = $this->conn->query($sql);
			return $hits_list;
		}
		//获取视频信息
		function getfoodinfor(){
			$sql_ft="select * from foodtype";
			$data = $this->conn->query($sql_ft);
			$f_list=array();
			foreach($data as $one)
			{
			$sql="select * from foods where tid=".$one['tid']." order by fid desc limit 0,6";

				$flist=array();
				$flist['tid']=$one['tid'];
				$flist['typename']=$one['typename'];
				$flist['list']=$this->conn->query($sql);
				$f_list[]=$flist;
			}
			return $f_list;
		}

		function getfoodlist($id){
			$sql="select * from foodtype where tid=".$id;
			$list=$this->conn->query($sql);
			$food_list=array();
			$ftsql="select * from foods where tid=".$id;
			$foodlist=array();
			$foodlist['tid']=$list['tid'];
			$foodlist['typename']=$list['typename'];
			$foodlist['list']=$this->conn->query($ftsql);
			$food_list[]=$foodlist; 
			return $food_list;
		}

		function fetch_one($sql,$result_type=MYSQL_ASSOC)
		{
		    $result=mysql_query($sql);
		    if ($result && mysql_num_rows($result)>0)
		    {
		        return mysql_fetch_array($result,$result_type);
		    }
		    else
		    {
		        return false;
		    }
		}

		function getfoodshow($id){
			$sql='select foods.*,comments.* from foods left join comments on foods.fid=comments.fid where foods.fid='.$id.'';
   			$show=$this->fetch_one($sql);
   			return $show;
		}
	}

?>